using System;
using System.Text.Json.Serialization;

namespace WpfApp1.Core
{
    public class ClipboardItem
    {
        [JsonPropertyName("id")]
        public string Id { get; set; } = string.Empty;
        
        [JsonPropertyName("content")]
        public string Content { get; set; } = string.Empty;
        
        [JsonPropertyName("device_id")]
        public string DeviceId { get; set; } = string.Empty;
        
        [JsonPropertyName("timestamp")]
        public long Timestamp { get; set; }

        [JsonIgnore]
        public string Time => DateTimeOffset.FromUnixTimeMilliseconds(Timestamp).LocalDateTime.ToString("yyyy-MM-dd HH:mm:ss");

        [JsonIgnore]
        public string FormattedTime
        {
            get
            {
                var dateTime = DateTimeOffset.FromUnixTimeMilliseconds(Timestamp).LocalDateTime;
                var today = DateTime.Today;
                
                if (dateTime.Date == today)
                {
                    return dateTime.ToString("HH:mm:ss");
                }
                else if (dateTime.Date == today.AddDays(-1))
                {
                    return "昨天 " + dateTime.ToString("HH:mm");
                }
                else if (dateTime.Year == today.Year)
                {
                    return dateTime.ToString("MM-dd HH:mm");
                }
                else
                {
                    return dateTime.ToString("yyyy-MM-dd HH:mm");
                }
            }
        }

        [JsonIgnore]
        public string DeviceIcon => IsCurrentDevice ? "Desktop" : "Cellphone";

        [JsonIgnore]
        public string DeviceDisplayName => IsCurrentDevice ? "电脑" : "手机";

        [JsonIgnore]
        public bool IsCurrentDevice => DeviceId == "PC";
    }
} 